package com.example.demo.utils;


import org.springframework.scheduling.annotation.Scheduled;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 生产HBase需要的数据
 * @author WZH
 * @create 2021-10-24 20:58
 * @desc
 **/
public class DataProducer {
    public static final String TABLE_NAME = "WD_TABLE";
    public static final String Column_FAMILY = "WD_DATA";
    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmssSSS");

    public void dataProducer() {
        // 5种温度传感器 WD000 WD001 WD002 WD003 WD004
        int SensorType =5;
        int count=1000;
        for (int j = 0; j < SensorType; j++) {
            for (int i = 0; i < count; i++) {
                String timeStamp = simpleDateFormat.format(new Date());
                String sensorId = "WD00" + j;
                String rowkey = sensorId + timeStamp;
                try {
                    HBaseUtils.addRowData(TABLE_NAME, rowkey, Column_FAMILY, "time", timeStamp);
                    HBaseUtils.addRowData(TABLE_NAME, rowkey, Column_FAMILY, "sensorId", sensorId);
                    HBaseUtils.addRowData(TABLE_NAME, rowkey, Column_FAMILY, "value", String.valueOf(20 + Math.random() * 3));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    public static void main(String[] args) {
        DataProducer dataProducer = new DataProducer();
        dataProducer.dataProducer();
    }
}
